package Operation;

import Book.BookList;

import java.util.Scanner;

public class RetuenOperation implements ioperation{
    public void work(BookList bookList) {
        System.out.println("归还图书！");
        //输入归还的书的名字
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的书的名字");
        String name = scanner.nextLine();

        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(name.equals(bookList.getBooks(i).getName())){

                //书架存在的书被借出
                if(bookList.getBooks(i).getisIfBorrowed() == true){
                    //成功归还，并且将书的状态置为flase，直接退出
                    bookList.getBooks(i).setIfBorrowed(false);
                    System.out.println("成功归还"+ "《"+ name + "》")
                }
            }else {
                //该书存在但未被借出
                System.out.println("《"+ name + "》" + "该书未被借出");
            }
        }
        //遍历书架未找到该书
        System.out.println("未找到"+ "《"+ name + "》");
    }
}
